import { Directive } from 'vue'

export const vCopy: Directive = {
  mounted(el: HTMLElement, binding) {
    el.addEventListener('click', () => {
      const text = binding.value || el.textContent
      navigator.clipboard.writeText(text).then(() => {
        // 可以添加提示
        console.log('复制成功')
      }).catch(err => {
        console.error('复制失败:', err)
      })
    })
  }
}

// 使用方式: <div v-copy="textToCopy">点击复制</div>